{% extends "base.html" %}

{% set active_page = "Home" %}

{% block body %}
    <div class="row">

    	
    	<div class="col-lg-2 col-md-4 col-sm-6">
			<h3></h3>
			<div style="max-width: 300px; margin: 0 auto;">
    			<img width="100%" height="auto" style="margin-top: 80px" src="{{ url_for('static', filename='fact_logo.png') }}"><br />
			</div>
    	</div>

    	<div class="col-lg-4 col-md-8 col-sm-6">
    		<h3>General Facts</h3>
    		<table class="table table-responsive table-hover table-bordered" style="border-spacing: 10px;">
    			<tr>
    				<td class="active" style="text-align: left; padding:5px">firmware samples</td>
    				<td class="active" style="text-align: right; padding:5px">{{ general_stats['number_of_firmwares'] | nice_number }}</td>
    			</tr>    			
    			<tr>
    				<td class="active" style="text-align: left; padding:5px">firmware total size</td>
    				<td class="active" style="text-align: right; padding:5px">{{ general_stats['total_firmware_size'] | number_format }}</td>
    			</tr>
    			<tr>
    				<td class="active" style="text-align: left; padding:5px">firmware average size</td>
    				<td class="active" style="text-align: right; padding:5px">{{ general_stats['average_firmware_size'] | number_format }}</td>
    			</tr>    			
    			<tr>
    				<td class="active" style="text-align: left; padding:5px">unique included files</td>
    				<td class="active" style="text-align: right; padding:5px">{{ general_stats['number_of_unique_files'] | nice_number }}</td>
    			</tr>
    			<tr>
    				<td class="active" style="text-align: left; padding:5px">unique included files total size</td>
    				<td class="active" style="text-align: right; padding:5px">{{ general_stats['total_file_size'] | number_format }}</td>
    			</tr>
    			<tr>
    				<td class="active" style="text-align: left; padding:5px">unique included files average size</td>
    				<td class="active" style="text-align: right; padding:5px">{{ general_stats['average_file_size'] | number_format }}</td>
    			</tr>
    			<tr>
    				<td class="active" style="text-align: left; padding:5px">statistic generation time</td>
    				<td class="active" style="text-align: right; padding:5px">{{ general_stats['benchmark'] | nice_number }} s</td>
    			</tr>  
    		</table>
    	</div>

    	{% if (latest_firmware_submissions | length) > 0 %}
    	<div class="col-lg-6">
    		<h3>Latest Submissions</h3>
    		Showing {{ latest_firmware_submissions | length }} out of <b>{{ general_stats['number_of_firmwares'] | nice_number }}</b> firmwares in the database.
    		<table class="table table-responsive table-hover table-bordered" style="border-spacing: 10px;">
    			<tr>
    				<th class="success active" style="text-align: center; padding:5px">Submission Time </th>
    				<th class="success active" style="text-align: center; padding:5px">Firmware </th>
    			</tr>
        	{% for firmware in latest_firmware_submissions %}
            	<tr>
            		<td class="active clickable" onclick="location.href='/analysis/{{ firmware['_id'] }}'"> {{ firmware[3] | nice_unix_time | safe }} </td>
                	{{ firmware | firmware_detail_tabular_field | safe }}
            	</tr>
        	{% endfor %}
        	</table>
    	</div>
    	{% endif %}

    	{% if (latest_comments | length) > 0 %}
    	<div class="col-lg-6">
    		<h3>Latest Comments</h3>
    		<table class="table table-responsive table-hover table-bordered" style="border-spacing: 10px;">
    			<tr>
    				<th class="success active" style="text-align: center; padding:5px;">Submission Time </th>
    				<th class="success active" style="text-align: center; padding:5px;">Author </th>
    				<th class="success active" style="text-align: center; padding:5px">Comment </th>
    			</tr>
        	{% for comment in latest_comments %}
            	<tr>
            		<td class="active clickable" onclick="location.href='/analysis/{{ comment.uid }}'"> {{ comment.time|int|nice_unix_time }} </td>
                	<td class="active clickable" onclick="location.href='/analysis/{{ comment.uid }}'"> {{ comment.author }} </td>
                	<td class="active clickable" onclick="location.href='/analysis/{{ comment.uid }}'" style="margin:0; padding:0;">
                        <pre style="white-space: pre-wrap;">{{ comment.comment|urlize }}</pre>
                    </td>
            	</tr>
        	{% endfor %}
        	</table>
    	</div>
    	{% endif %}

        {# latest_comparison_results #}
    	{% if (latest_comparison_results | length) > 0 %}
    	<div class="col-lg-6">
    		<h3>Latest Comparisons</h3>
    		<table class="table table-responsive table-hover table-bordered" style="border-spacing: 10px;">
    			<tr>
    				<th class="success active" style="text-align: center; padding:5px">Submission Time </th>
    				<th class="success active" style="text-align: center; padding:5px">Comparisons </th>
    			</tr>
        	{% for id, hids, submission_date in latest_comparison_results %}
                <tr>
            		<td class="active clickable" onclick="location.href='/compare/{{ id }}'"> {{ submission_date | nice_unix_time | safe }} </td>
                    <td class="active clickable" onclick="location.href='/compare/{{ id }}'">
                        {%  for uid in hids %}
                            {{ hids[uid] }}
                            <div><font face="courier"  style="font-size:12px">{{ uid }}</font></div>
                        {% endfor %}
                    </td>
                </tr>
        	{% endfor %}
        	</table>
    	</div>
    	{% endif %}

    </div>

{% endblock %}
